#******************************************************************
#
# Copyright 2014 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

##
# Simulator build script
##

import os, sys
Import('env')

lib_env = env.Clone()
SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
simulator_env = lib_env.Clone()

#Raml Parser
SConscript('ramlparser/SConscript')

target_os = env.get('TARGET_OS')
######################################################################
# Build flags
######################################################################
simulator_env.AppendUnique(CPPPATH = ['inc', 'src/client-controller', 'src/service-provider', 'src/common'])
simulator_env.AppendUnique(CPPPATH = [
		'../../resource/include/',
		'../../resource/csdk/stack/include',
		'../../resource/csdk/ocrandom/include',
		'../../resource/csdk/logger/include',
		'../../resource/oc_logger/include',
		'./ramlparser/raml',
		'./ramlparser/raml/model',		
		'./ramlparser/raml/jsonSchemaParser',	
		'../../extlibs/yaml/yaml/include'
		])

# Including Java path for building JNI files
try:
	os.environ['JAVA_HOME']
except KeyError:
	print '''
*************************************** Error *********************************
* JAVA_HOME environment variable not set                                      
* Simulator has dependency on java, Please set environment variable JAVA_HOME
*******************************************************************************
	'''
	sys.exit(1)
	
java_headers = [os.path.join(os.environ['JAVA_HOME'], 'include')]
java_headers.append(os.path.join(java_headers[0], 'win32'))
java_headers.append(os.path.join(java_headers[0], 'linux'))
java_headers.append(os.path.join(java_headers[0], 'solaris'))
simulator_env.AppendUnique(CPPPATH = java_headers)

simulator_env.AppendUnique(CPPPATH = ['../../extlibs/cjson'])
simulator_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap','RamlParser','YamlParser'])
simulator_env.AppendUnique(LIBS = ['pthread'])

simulator_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])

######################################################################
# Source files and Targets
######################################################################
simulator_src = [env.Glob('src/*.cpp')
                 ,env.Glob('src/*/*.cpp')
                 ,env.Glob('java/jni/*.cpp')
                ]
simulatorsdk = simulator_env.SharedLibrary('SimulatorManager', simulator_src)

simulator_env.InstallTarget(simulatorsdk, 'libSimulator')

#Build sample application
SConscript('examples/server/SConscript')
SConscript('examples/client-controller/SConscript')
